// store/index.ts
import { createStore, Store } from 'vuex';
import { user, UserState, UserMutations, UserActions } from './module/user';
import { LoginState, LoginActions, LoginMutations } from './module/login';  // 添加 LoginActions 和 LoginMutations 导入
import { RegisterState, RegisterActions, RegisterMutations } from './module/register';  // 添加 RegisterActions 和 RegisterMutations 导入

export interface RootState {
    user: UserState;
    login: LoginState;
    register: RegisterState;
}

export const store = createStore({
    modules: {
        user,
        login: {
            namespaced: true,
            state: {
                isLogin: false,
            },
            mutations: {
                // 定义 login 模块的 mutations
            } as LoginMutations,
            actions: {
                // 定义 login 模块的 actions
            } as LoginActions,
        },
        register: {
            namespaced: true,
            state: {
                isRegister: false,
            },
            mutations: {
                // 定义 register 模块的 mutations
            } as RegisterMutations,
            actions: {
                // 定义 register 模块的 actions
            } as RegisterActions,
        }
    },
});

export type AppStore = Store<RootState> & {
    commit: UserMutations & LoginMutations & RegisterMutations;  // 合并 mutations 类型
    dispatch: UserActions & LoginActions & RegisterActions;  // 合并 actions 类型
    state: RootState & {
        user: UserState;
    };
};
